﻿using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;

namespace BunnyEater.WebAPI.Extensions
{
    /// <summary>
    /// Swagger中Guid类型的Schema过滤器，为Guid类型提供示例值和默认值
    /// </summary>
    public class GuidSchemaFilter : ISchemaFilter
    {
        /// <summary>
        /// 应用Schema过滤器
        /// </summary>
        /// <param name="schema">OpenAPI Schema对象</param>
        /// <param name="context">Schema过滤器上下文</param>
        public void Apply(OpenApiSchema schema, SchemaFilterContext context)
        {
            if (context.Type == typeof(Guid) || context.Type == typeof(Guid?))
            {
                schema.Example = new OpenApiString(Guid.Empty.ToString());
                schema.Default = new OpenApiString(Guid.Empty.ToString());
            }
        }
    }
}
